class Solution(object):
    def maxProfit1(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        res = 0
        if not prices:
            return res
        max_last = []
        flag = -100000
        for i in xrange(len(prices) - 1, -1, -1):
            num = prices[i]
            if num > flag:
                flag = num
            max_last.insert(0, flag)
        for i in xrange(len(prices) - 1):
            res = max(res, max_last[i + 1] - prices[i])
        return res

    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """

if __name__ == '__main__':
    nums = [7,1,5,3,6,4]
    aa = Solution()
    print aa.maxProfit(nums)